home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
ai
/
fuzzy
/
list
< prev
next >
Wrap
Text File
|
1986-10-20
|
2KB
|
60 lines
{
List Utility Functions
}
append( [], Str2, Str2 ).
append( [Head|Tail], Str2, [Head|Result] ) :- append( Tail, Str2, Result ).
member( Element, [Element|_] ).
member( Element, [_|Tail] ) :- member( Element, Tail ).
replace(A,B,C,D) :- var(A), !, replace(B,A,D,C).
replace(A,B,C,D) :- var(C), !, replace(B,A,D,C).
replace( _, _, [], [] ).
replace( Match, Substitute, [Match|In_tail], [X|Out_tail] ) :- !, X=Substitute,
replace( Match, Substitute, In_tail, Out_tail ).
replace( Match, Substitute, [Head|In_tail], [Head|Out_tail] ) :-
replace( Match, Substitute, In_tail, Out_tail ).
starts( [], _ ).
starts( [Head|Tail1], [Head|Tail2] ) :- starts( Tail1, Tail2).
howmany(A,B,C) :- var(A), !, howmany2(A,B,C).
howmany( _, [], 0 ).
howmany( Match, [Match|Tail], Count ) :- !,
howmany( Match, Tail, Count2 ), Count is Count2 + 1 .
howmany( Match, [_|Tail], Count ) :- howmany(Match, Tail, Count).
howmany2(_,[],_) :- !, fail.
howmany2( Match, [Match|Rest], Count ) :- howmany(Match, [Match|Rest], Count).
howmany2( Match, [First|Rest], Count ) :- extract(First, Rest, New),
howmany2(Match, New, Count).
subset([],_).
subset([Match|Others],List) :- member(Match, List), remove(Match, List, New),
subset(Others, New).
remove(_,[],[]).
remove(Match, [Match|Tail], Tail) :- !.
remove(Match, [Head|Tail], [Head|New]) :- remove(Match, Tail, New).
slice(Piece, Pie) :- starts(Piece, Pie).
slice(Piece, [_|Not_eaten]) :- slice(Piece, Not_eaten).
nth(A,B,C) :- var(A), !, nth2(A,B,C).
nth(1,[Match|_],Match) :- !.
nth(Count, [Head|Tail], Match) :- Count1 is Count-1, nth(Count1, Tail, Match).
nth2(1,[Match|_],Match) :- !.
nth2(Count,[_|Tail],Match) :- nth2(Count2, Tail, Match), Count is Count2 + 1 .
undup([],[]).
undup([El|Old],[El|New]) :- extract(El, Old, New2), undup(New2, New).
extract(_, [], []).
extract(Match, [Match|Tail], New_list) :- extract(Match, Tail, New_list), !.
extract(Match, [Head|Tail], [Head|New_list]) :- extract(Match, Tail, New_list).